using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class PlantSection_RecommendThreads : YuanlinUserControl,
        IPageIndexChangedEventHandler
    {
        protected Repeater list;
        protected AjaxPager pager;
        public int sectionId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.PlantSectionId);
        public int categoryType = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryType);
        public int categoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryId);

        private int SectionId
        {
            get
            {
                object o = ViewState["SectionId"];
                if (o != null)
                {
                    return int.Parse(o.ToString());
                }
                return 0;
            }
            set
            {
                ViewState["SectionId"] = value;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            this.ID = pager.TargetControlID;

            if (!Page.IsPostBack)
            {
                SectionId = sectionId;
                BindData(pager.PageIndex, pager.PageSize);
            }
        }

        public void BindData(int pageIndex, int pageSize)
        {
            if (list == null)
            {
                return;
            }
            EntityList threads = BusinessManager.GetPlantSection_ThreadList(RequestHelper.BuildGetPlantSection_RecommendThreadListRequest(this.SectionId,categoryType,categoryId, pageIndex - 1, pageSize));

            list.DataSource = threads;
            list.DataBind();

            pager.TotalRecords = threads.TotalCount;

        }
    }
}